import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';

//列表数据
export const columns: BasicColumn[] = [
   {
    title: '物料名称',
    align:"center",
    dataIndex: 'name'
   },
   {
    title: '物料/产品',
    align:"center",
    dataIndex: 'itemOrProduct_dictText'
   },
   {
    title: '物料编码',
    align:"center",
    dataIndex: 'code'
   },
   {
    title: '规格型号',
    align:"center",
    dataIndex: 'specification'
   },
   {
    title: '单位',
    align:"center",
    dataIndex: 'unitOfMeasure',
    customRender: ({ text }) => {
      return render.renderDict(text, 'unit_of_measure');
    },
   },
   {
    title: '是否启用',
    align:"center",
    dataIndex: 'enableFlag_dictText'
   },
];

export const bomColumns: BasicColumn[] = [
   {
    title: '物料名称',
    align:"center",
    dataIndex: 'bomItemName'
   },
   {
    title: '物料/产品',
    align:"center",
    dataIndex: 'itemOrProduct_dictText'
   },
   {
    title: '物料编号',
    align:"center",
    dataIndex: 'bomItemCode'
   },
   {
    title: '物料规格',
    align:"center",
    dataIndex: 'bomItemSpec'
   },
   {
    title: '物料使用比例',
    align:"center",
    dataIndex: 'quantity'
   },
   {
    title: '单位',
    align:"center",
    dataIndex: 'unitOfMeasure',
    customRender: ({ text }) => {
      return render.renderDict(text, 'unit_of_measure');
    },
   },
];


//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label:'物料名称',
    field:'name',
    component:'Input'
  },
  {
    label:'物料编码',
    field:'code',
    component:'Input'
  }
];

//物料组成列表查询
export const searchBomSchema: FormSchema[] = [

]


//表单数据
export const formSchema: FormSchema[] = [
  {
    label:'二维码',
    field:'qrcode',
    component:'Input',
    slot:'fileCode',
    colProps:{
      span:24
    },
    ifShow:({values})=>{
      return !!values.qrcode
    }
  },
  {
    label: '物料名称',
    field: 'name',
    component: 'Input',
    required:true
  },
  {
    label: '物料编码',
    field: 'code',
    component: 'Input',
    componentProps:{
      placeholder:"默认自动生成"
    }
  },
  {
    label: '规格型号',
    field: 'specification',
    component: 'Input'
  },
  {
    label: '尺寸',
    field: 'size',
    component: 'Input'
  },
  {
    label: '单位',
    field: 'unitOfMeasure',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"unit_of_measure"
     },
  },
  {
    label: '物料类型',
    field: 'wmItemTypeId',
    component: 'JTreeSelect',
    componentProps:{
        dict:"wm_item_type,name,id",
        pidValue:"1829776126609260545",
    },
  },
  {
    label: '是否启用',
    field: 'enableFlag',
    defaultValue: "Y",
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"enable_flag",
        type: "radio"
     },
  },
  {
    label:'附件',
    field:'file',
    component:'JUpload'
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];


export const detailFormSchema: FormSchema[] = [
  {
    label: '产品名称',
    field: 'name',
    component: 'Input',
    componentProps:{
      allowClear:false,
      readOnly:true
    }
  },
  {
    label: '物料编码',
    field: 'code',
    component: 'Input',
    show:false,
    componentProps:{
      placeholder:"默认自动生成"
    }
  },
  {
    label: '规格型号',
    field: 'specification',
    component: 'Input',
    componentProps:{
      allowClear:false,
      readOnly:true
    }
  },
  {
    label: '尺寸',
    field: 'size',
    component: 'Input',
    componentProps:{
      allowClear:false,
      readOnly:true
    }
  },
  {
    label:'附件',
    field:'file',
    component:'Input',
    slot:'fileSlot'
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];


export const BomFormSchema:FormSchema[]=[
  {
    label: '物料编号',
    field: 'bomItemCode',
    component: 'Input',
    componentProps:{
      disabled: true
    }
   },
  {
    label: '物料名称',
    field: 'bomItemName',
    component: 'Input',
    componentProps:{
      disabled: true
    }
   },
   {
    label: '物料规格',
    field: 'bomItemSpec',
    component: 'Input',
    componentProps:{
      disabled: true
    }
   },
   {
    label: '物料/产品',
    field: 'itemOrProduct_dictText',
    component: 'Input',
    componentProps:{
      disabled: true
    }
   },
   {
    label: '单位',
    field: 'unitOfMeasure',
    component: 'Input',
    componentProps:{
      disabled: true
    },
    render:({model,field})=>{
      return render.renderDict(model[field],'unit_of_measure')
    }
   },
   {
     label: '物料使用比例',
     field: 'quantity',
     component: 'Input'
   },
  {
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	}
]

// 高级查询数据
export const superQuerySchema = {
  name: {title: '产品物料名称',order: 0,view: 'text', type: 'string',},
  code: {title: '产品物料编码',order: 1,view: 'text', type: 'string',},
  specification: {title: '规格型号',order: 2,view: 'text', type: 'string',},
  unitOfMeasure: {title: '单位',order: 3,view: 'list', type: 'string',dictCode: 'unit_of_measure',},
  wmItemTypeId: {title: '物料类型ID',order: 5,view: 'sel_tree', type: 'string',dict: 'wm_item_type,name,id', pidValue: '1829776126609260545',},
  enableFlag: {title: '是否启用',order: 9,view: 'radio', type: 'string',dictCode: 'enable_flag',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
